package org.example.j1110nm2;

import org.apache.catalina.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/user")
@RestController
public class Test {
    @RequestMapping(value="/111",method = RequestMethod.GET)
    public String hello(){
        return "hello,springboot架构";
    }

    @RequestMapping("/r1")
    public String r1(String name){
        return "r1接收到参数name:"+name;
    }

    @RequestMapping("/r2")
    public String r2(Integer age){
        return "r2接收到参数age:"+age;
    }

    @RequestMapping("/r3")
    public String r3(String name,Integer age){
        return "name"+name+"r3接收到参数age:"+age;
    }

    @RequestMapping("/r4")
    public String r4(UserInfo user){
        return user.toString();
    }

    @RequestMapping("/r5")
    public String r5(@RequestParam(value = "name",required = false) String username, @RequestParam("name") Integer userage){
        return "name:"+username+"r3接收到参数age:"+userage;
    }

    @RequestMapping("/r6")
    public String r6(String[] arr){
        return Arrays.toString(arr);
    }

    @RequestMapping("/r7")
    public String r7(@RequestParam("list") List<String> list){
        if(list!=null){
            return list.toString();
        }
        return "list是空的";
    }

    @RequestMapping("/r8")
    public String r8(@RequestBody UserInfo userInfo){
        return userInfo.toString();
    }

    @RequestMapping("/r9/{articleid}")
    public String r9(@PathVariable Integer articleid){
        return "articleid:"+articleid;
    }

    @RequestMapping("/r10/{name}/{age}")
    public String r10(@PathVariable String name,@PathVariable Integer age){
        return "name:"+name+",age:"+age;
    }

    @RequestMapping("/r11")
    public String r11(@RequestPart MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        file.transferTo(new File("D:/temp"+fileName));
        return "获取到的这个file:"+file.getOriginalFilename();
    }


}
